package pap.gui;

import java.awt.Graphics;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JPanel;

import pap.utils.Constants;

public class GUI extends JFrame {

	private static final long serialVersionUID = 9105980061064994254L;
	private GUIPanel panel;

	/**
	 * GUI Initialization
	 */
	public GUI() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setTitle("N-Body Problem");
		setSize(Constants.START_PX_WIDTH, Constants.START_PX_HEIGHT);
		setResizable(true);
		panel = new GUIPanel();
		getContentPane().add(panel);
	}

	public void drawShape(List<IShape> shapes) {
		panel.drawShape(shapes);
	}

	private static class GUIPanel extends JPanel {

		private static final long serialVersionUID = 2431762794731729675L;
		private List<IShape> shapes;

		public void paint(Graphics g) {

			g.setColor(Constants.SPACE_COLOR);
			g.fillRect(0, 0, getSize().width, getSize().height);

			if (shapes != null) {
				for (IShape s : shapes) {
					s.draw(g);
				}
			}

		}

		/**
		 * Updating of the bodies's position on the screen
		 * 
		 * @param sh
		 */
		public void drawShape(List<IShape> sh) {
			shapes = sh;
			repaint();
		}
	}
}
